define(['jquery','cm'],function(){
    $('footer').load('../html/footer.html')
class getCard {
    constructor() {
        this.injure = document.querySelector('#recipient-name')
        this.password = document.querySelector('#message-text')
        this.message = document.querySelector('#message-text1')
        this.button1 = document.querySelector('#button1')
        this.phone = document.querySelector('#recipient-phone')
        this.span = document.querySelector('.jugeSpan')
        this.span2 = document.querySelector('.keyWord')
        this.span3 = document.querySelector('.sureKey')
        this.span4 = document.querySelector('.jugePhone')
        this.getSrc=['../imgaes/图1.jpg','../imgaes/图2.jpg','../imgaes/图3.jpg','../imgaes/图4.jpg','../imgaes/图5.jpg','../imgaes/图6.png']
        // console.log(this.box2)
        this.jugePhone = /^\d{11}$/
        this.jugePass = /^[a-zA-Z][a-zA-Z0-9]{5,11}/
        this.agree = document.querySelector('.agree input')

        this.ragister()
        this.getNumber()
        this.charge()
       
    }
    ragister() {
        this.button1.addEventListener('click', () => {
            var d = this.jugePass.test(this.password.value)
            var c = this.jugePhone.test(this.phone.value);
            let arr = this.getNumber()
            var infor = {
                userName: this.injure.value,
                password: this.password.value,
                phoneNumber: this.phone.value,
                src:this.getSrc[arr.length]
            }
            // let arr = this.getNumber()
            console.log(arr)

            if (arr.length > 0) {
                var f = arr.some((item) => {
                    return item.userName == this.injure.value && item.phoneNumber == this
                        .phone.value
                })
                if (!f && this.injure.value != '' && d && (this.password
                    .value == this.message.value && c && this.agree.checked)) {
                    arr.push(infor)
                    alert('恭喜您，注册成功')
                    window.location.href = '../html/login.html'
                } else if (this.password.value == '' || !d) {
                    alert('请重新输入密码或用户名')
                } else if (f) {
                    alert('请重新输入用户名或手机号')
                } else if (this.password.value != this.message.value) {
                    alert('请输入一致的密码')
                } else if (!c) {
                    alert('请输入正确的手机号')
                }
                else if (!this.agree.checked) {
                    alert('请勾选协议')
                }
            } else if (!f && this.injure.value != '' && d && (this.password
                .value == this.message.value && c)) {
                arr.push(infor)
                alert('恭喜您注册成功')
                window.location.href = '../html/login.html'
            } else if (this.password.value == '' || !d) {
                alert('请重新输入密码或用户名')
            } else if (this.password.value != this.message.value) {
                alert('请输入一致的密码')
            } else if (!c) {
                alert('请输入正确的手机号')
            }
            localStorage.setItem('curt', JSON.stringify(arr))

        })
    }
    getNumber() {
        return JSON.parse(localStorage.getItem('curt')) || []
    }
    charge() {

        this.injure.addEventListener('blur', () => {
            let arr = this.getNumber()
            if (arr.length > 0) {
                var f = arr.some((item) => {
                    return item.userName == this.injure.value
                })
                if (f) {
                    this.span.className = 'active'
                    this.span.innerHTML = '该账号已注册过'
                } else if (this.injure.value != '') {
                    this.span.innerHTML = '该账号可以注册'
                    this.span.className = 'activeTure'
                } else {
                    this.span.innerHTML = '请输入用户名'
                    this.span.className = 'active'
                }
            } else if (this.injure.value != '') {
                this.span.innerHTML = '该账号可以注册'
                this.span.className = 'activeTure'
            } else {
                this.span.innerHTML = '请输入用户名'
                this.span.className = 'active'
            }
        })
        this.password.addEventListener('blur', () => {
            // var c='313223'
            var d = this.jugePass.test(this.password.value)
            console.log(d)

            if (!d) {
                this.span2.className = 'active'
                this.span2.innerHTML = '请重新输入注册密码'
            } else {
                this.span2.className = 'activeTure'
                this.span2.innerHTML = '该密码可以注册'
            }
        })
        this.message.addEventListener('blur', () => {
            if (this.password.value == this.message.value && this.password.value != '') {
                this.span3.className = 'activeTure'
                this.span3.innerHTML = '正确'
            } else {
                this.span3.className = 'active'
                this.span3.innerHTML = '请输入一致的密码'
            }
        })
        this.phone.addEventListener('blur', () => {
            let arr = this.getNumber()
            var c = this.jugePhone.test(this.phone.value)
            if (arr.length > 0) {
                var f = arr.some((item) => {
                    return item.phoneNumber == this.phone.value
                })
                if (f) {
                    this.span4.className = 'active'
                    this.span4.innerHTML = '该手机号已注册'
                } else if (!c) {
                    this.span4.className = 'active'
                    this.span4.innerHTML = '请输入11位数字的手机号'
                } else {
                    this.span4.className = 'activeTure'
                    this.span4.innerHTML = '该手机号可以注册'
                }
            } else if (!c) {
                this.span4.className = 'active'
                this.span4.innerHTML = '请输入11位数字的手机号'
            } else if (c) {
                this.span4.className = 'activeTure'
                this.span4.innerHTML = '该手机号可以注册'
            }

        })
    }
  


}
new getCard()

})